home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 2
/
Nebula Two.iso
/
SourceCode
/
Tutorial
/
Cookbook
/
20.alarm
/
MyObject.m
< prev
next >
Wrap
Text File
|
1995-06-12
|
3KB
|
139 lines
/* Generated by Interface Builder */
#import <string.h>
#import <math.h>
#import <sys/time.h>
#import "MyObject.h"
#import <appkit/Form.h>
#import <appkit/Application.h>
#import <appkit/Panel.h>
#import <appkit/nextstd.h>
@implementation MyObject
void update (teNum, now, myself)
DPSTimedEntry teNum;
double now;
id myself;
{
[myself doTimedEntry];
}
+ new
{
self = [super new];
message = FALSE;
stop = FALSE;
return self;
}
- startTimedEntry
{
clockTE = DPSAddTimedEntry(60.0, &update, self, NX_MODALRESPTHRESHOLD);
return self;
}
- stopTimedEntry
{
DPSRemoveTimedEntry (clockTE);
return self;
}
- doTimedEntry
{
static int localCounter;
localCounter += 1;
[self displayCurrentTime];
if ((hour == sliderHour) && (min >= sliderMin) && (min < sliderMin+10)) {
if (!stop ){
system("/usr/bin/sndplay /NextLibrary/Sounds/Basso.snd");
system("/usr/bin/sndplay /tmp/sample.snd");
}
}
}
// Good programming practice. Free what you create!
- free
{
[self stopTimedEntry];
return [super free];
}
- setAlarmHour:anObject
{
alarmHour = anObject;
[self startTimedEntry];
return self;
}
- setAlarmMin:anObject
{
alarmMin = anObject;
return self;
}
- setCurrentHour:anObject
{
currentHour = anObject;
[self displayCurrentTime];
return self;
}
- setCurrentMin:anObject
{
currentMin = anObject;
[self displayCurrentTime];
return self;
}
- setAlarm:sender
{
if (!message) {
[self recordMessage:self];
}
stop = FALSE;
// printf("Alarm Set at %d:%d\n", sliderHour, sliderMin);
return self;
}
- displayCurrentTime //
{
gettimeofday (¤tTime, NULL);
localTime = localtime (&(currentTime.tv_sec));
hour = localTime->tm_hour;
min = localTime->tm_min;
// sec = localTime->tm_sec;
[currentHour setIntValue:hour];
[currentMin setIntValue:min];
}
- recordMessage:sender
{
// call up sound editor and save to a file
// update the alarm list file
system("/NextDeveloper/Examples/SoundEditor/SoundEditor");
message=TRUE;
return self;
}
- stopAlarm:sender
{
stop = TRUE;
return self;
}
// get the value from the slider and set the alarm
- getValue:sender
{
sliderFloat = [sender floatValue];
sliderHour = floor(sliderFloat);
sliderMin = 60.0 * (sliderFloat - (float) sliderHour); // drop fraction
sliderMin = ((sliderMin + 2) / 5) * 5; // round to nearist 5 minute
[alarmHour setIntValue:sliderHour];
[alarmMin setIntValue:sliderMin];
return self;
}
@end